package com.jarich.morewore.model;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class TextDrawable extends Drawable {

    private final String text;
    private final Paint paint;
    private final Drawable icon;

    public TextDrawable(String text, Drawable d) {
        this.text = text;
        icon = d;
        this.paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(25f);
        paint.setAntiAlias(true);
        paint.setFakeBoldText(true);
        paint.setShadowLayer(6f, 0, 0, Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);  
    }

    public Bitmap toBitmap () {
        Bitmap bitmap = Bitmap.createBitmap(getIntrinsicWidth(), getIntrinsicHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap); 
        setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        draw(canvas);

        return bitmap;
    }
    

    @Override
    public void draw(Canvas canvas) {
        canvas.drawText(text, -30, -20, paint);
        Bitmap d = ((BitmapDrawable)icon).getBitmap();
        canvas.drawBitmap(d, -50, -150, paint);
        
    }

    @Override
    public void setAlpha(int alpha) {
        paint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        paint.setColorFilter(cf);
    }

	@Override
	public int getOpacity() {
		return 0;
	}
}